import org.sugar.sigslot.Glue;
class GlueTest
{

	public function new()
	{
		
	}

	public static function main(): Void
	{
		var t = new GlueTest();
		var o = new Other();
		
		trace('===Simple Example===');
		trace('BEFORE');
		t.voidArg();
		trace('AFTER');
		t.voidArg = Glue.joinVoid(t.voidArg, o.voidArg);
		t.voidArg();
		
		trace('===Matching Args===');
		t.oneArg = Glue.join1(t.oneArg,o.oneArg);
		t.oneArg(1);
		
		trace('===Recursive Overrides===');
		t.oneArg = Glue.join1(t.oneArg, o.oneArg);
		t.oneArg(2);
		
// 		this will throw a compiler error, unmatched arity
//		t.oneArg = Glue.join1(t.oneArg, o.voidArg); 
	
		trace('===Fixing Arity with Closures===');
		t.oneArg = Glue.join1(t.oneArg, function(x:Int) { return o.voidArg(); } );
		t.oneArg(2);
		

			
		trace('===Arity only matching===');
		// oneArgAlt has a different named argument "y", however it doesn't matter.
		t.oneArg = Glue.join1(t.oneArg, o.oneArgAlt);
		t.oneArg(3);
		

	}
	
	public dynamic function voidArg() { trace('hi'); }
	public dynamic function oneArg(x:Int) { trace('hi '+ x); }
	public dynamic function twoArg(x:Int, y:Int) { trace('hi ' + x + ' ' + y); }
}

class Other
{
	public function new();
	public function voidArg() { trace('other hi'); }
	public function oneArg(x:Int) { trace('other hi '+ x); }
	public function oneArgAlt(y:Int) { trace('other hi '+ y); }
	public function twoArg(x:Int, y:Int) { trace('other hi ' + x + ' ' + y); }
}